#!/usr/bin/python3

import subprocess

p = subprocess.Popen("ps -aux|grep '/usr/bin/python3 /opt/elasticsearch_test/manage.py runserver 0.0.0.0:80'",shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
num = 0
for i in iter(p.stdout.readline, 'b'):
    if not i:
        break
    output = i.decode('utf-8')
    print(output)
    num+=1
print(num)
if num < 3:
    subprocess.Popen("nohup python3  /opt/elasticsearch_test/manage.py  runserver 0.0.0.0:80 >>/dev/null 2>&1 &",shell=True)
    print('重启服务')
else:
    print('服务正常')
